package com.qf.blog.controller;

import com.qf.blog.commons.response.ResponseResult;
import com.qf.blog.service.ILetterService;
import com.qf.blog.vo.LetterVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/letter")
@Slf4j
public class LetterController {
    @Autowired
    ILetterService iLetterService;
    @RequestMapping("/detail")
    public String queryById(String id, Model model){
        List<LetterVo> letterVoList=iLetterService.queryById(id);
        model.addAttribute("letterVoList",letterVoList);
        return "/site/letter-detail";
    }
    @RequestMapping("/update")
    public String updateStatus(Integer id,Model model){
        List<LetterVo> letterVoList=iLetterService.updateStatus(id);
        model.addAttribute("letterVoList",letterVoList);
        return "/site/letter-detail";
    }
    @RequestMapping("/send")
    @ResponseBody
    public ResponseResult add(String toName, String content){
        iLetterService.add(toName,content);
        return ResponseResult.success();
    }
}
